{extend name="shared/layout" /}
{block name="title"}新增分组{/block}
{block name="css"}    
{/block}
{block name="javascript"}
    <script type="text/javascript">
        $(document).ready(function () {
            $("#ok").bind("click", Save);
            $("#cancel").bind("click", function () {
                parent.layer.close(parent.layer_add_index);
            });
        })

        function romveleft() {
            var itm = $("#selUnImages option:selected");
            itm.each(function () {
                $("#selImages").append("<option value='" + this.value + "'>" + this.text + "</option>");
                $(this).remove();
            });
        }

        function romveright() {
            var itm = $("#selImages option:selected");
            itm.each(function () {
                $("#selUnImages").append("<option value='" + this.value + "'>" + this.text + "</option>");
                $(this).remove();
            });
        }
    
        function Save() {
            layui.use(['layer'], function(){
                var layer = layui.layer;

                var name = $.trim($("input[name=name]").val());
                if (name.length == 0) {
                    layer.tips('分组名称不能为空！', 'input[name=name]', { tips: [2, '#78BA32'] });
                    return false;
                }

                var arr = Array();
                var itm = $("#selImages option");
                itm.each(function () {                    
                    arr.push(this.value);
                }); 
                                
                var load_index = layer.load(0, { shade: false });
                $.ajax({
                    type: "post",
                    url: "{:url('image/addgroup')}?t=" + new Date(),
                    data: { name:name,imageIds:arr.join(',') },
                    dataType: "json",
                    success: function (result) {
                        layer.close(load_index);
                        if (result.code == 0) {
                            layer.alert('保存成功！', function () {
                                if (typeof (parent.initTable) == "function")
                                    parent.initTable();
                                parent.layer.close(parent.layer_add_index)
                            });
                        } else {
                            layer.alert(result.msg);
                        }
                    }
                });
            });
        }
    </script>
{/block}
{block name="content"}
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-content">
                        <form method="post" id="fmNew" class="form-horizontal">
                            <div class="form-group">
                                <label class="col-sm-2 control-label">分组名称：</label>
                                <div class="col-sm-5">
                                    <input type="text" class="form-control" name="name" placeholder="请输入分组名称" />
                                </div>
                            </div>
                            <div class="form-group">
                                <div class="col-sm-4 col-sm-offset-2">
                                    图片列表
                                    <select class="form-control" id="selUnImages" style="height:300px;" multiple>
                                        {volist name="list" id="vo"}
                                            <option value="{$vo.id}">{$vo.image_name}</option>
                                        {/volist}
                                    </select>
                                </div>
                                <div class="col-sm-1 m-1-n" style="height:300px;padding-top:130px;">
                                    <input type="button" value="==>" onclick="romveleft();" />
                                    <br/><br />
                                    <input type="button" value="<==" onclick="romveright();" />
                                </div>
                                <div class="col-sm-4 m-l-n">
                                    已选图片
                                    <select class="form-control" id="selImages" style="height:300px;" multiple>
                                    </select>
                                </div>
                            </div>                            
                            <div class="hr-line-dashed"></div>
                            <div class="form-group">
                                <div class="col-sm-12 col-sm-offset-5">
                                    <button class="btn btn-primary" id="ok" type="button">提交</button>
                                    <button class="btn btn-white" id="cancel" type="button">取消</button>
                                </div>
                            </div>
                        </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>        
{/block}